/** 
 * Copyright (c) 2012 Beny Information Technology Co., Ltd. All Rights Reserved. 
 * <p>
 * Project Name:  奔逸协同工作平台
 * FileName：g.beny.framework.PublicAction.java 
 * Created On: 2012-7-29 上午12:12:56
 * Description: 
 * @author gson
 * @version 1.0
 * <p>
 * Modifier： 2012-7-29 上午12:12:56
 * Modify Time： 2012-7-29 上午12:12:56
 */
package g.beny.framework;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nutz.mvc.View;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Filters;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.view.JspView;

import g.beny.framework.constant.Constant;
import g.beny.framework.util.ImageCodeBulider;
import g.beny.framework.web.ActionSupport;

/**
 * 系统公告请求，不受资源权限控制
 * 
 * @ClassName: PublicAction
 * @Description: TODO
 * @author gson
 * @date 2012-7-29 上午12:12:56
 * 
 */
@Filters
public class PublicAction extends ActionSupport {
	/**
	 * 系统首页
	 * 
	 * @methodName index
	 * @Description
	 * @CreatedOn 2012-7-29 上午12:20:19
	 * @author gson
	 * @param req
	 * @return
	 */
	@At("/index")
	public View index(HttpServletRequest req) {
		if (req.getSession().getAttribute(Constant.Config.PRO_USER_SESSION_KEY) == null) {
			return new JspView("page.login");
		}
		return new JspView("page.index");
	}

	/**
	 * 系统管理首页
	 * 
	 * @methodName manage
	 * @Description 系统管理首页 /manage.do
	 * @CreatedOn 2012-7-29 上午12:15:31
	 * @author gson
	 * @param req
	 * @return
	 */
	@At("/manage")
	public View manage(HttpServletRequest req) {
		if (req.getSession().getAttribute(Constant.Config.MGR_USER_SESSION_KEY) == null) {
			return new JspView("page.manage.login");
		}
		return new JspView("page.manage.index");
	}

	/**
	 * 验证码
	 * 
	 * @methodName code
	 * @Description 生成验证码 /code.do
	 * @CreatedOn 2012-7-28 下午10:16:25
	 * @author gson
	 * @param req
	 * @param rsp
	 */
	@At("/code")
	@Ok("Raw:image/jpeg")
	public byte[] code(HttpServletRequest req, HttpServletResponse rsp) {
		ImageCodeBulider builder = ImageCodeBulider.gen();
		setSesAttr(Constant.Config.VERIFICATION_CODE_KEY, builder.getCode());
		return builder.getImgData();
	}
}
